import { getNotifications } from '../requests'

export const CHANGE_NOTIFICATIONS_READ_STATUS =
  'CHANGE_NOTIFICATIONS_READ_STATUS'
export const SET_NOTIFICATIONS = 'SET_NOTIFICATIONS'
export const MARK_AL_NOTIFICATIONS_AS_READ = 'MARK_AL_NOTIFICATIONS_AS_READ'

export const changeNotificationsReadStatus = id => {
  return {
    type: CHANGE_NOTIFICATIONS_READ_STATUS,
    payload: {
      id
    }
  }
}

export const markAllNotifitioncationsAsRead = () => {
  return {
    type: MARK_AL_NOTIFICATIONS_AS_READ
  }
}

const setNotifications = notifications => {
  return {
    type: SET_NOTIFICATIONS,
    payload: {
      notifications
    }
  }
}
export const getNotificationsAction = notifications => {
  return dispatch => {
    getNotifications().then(res => {
      if (res.data.code === 200) {
        dispatch(setNotifications(res.data.data))
      }
    })
  }
}
